#include <bits/stdc++.h>
#define MAXN 200 + 5
#define MAXM 5000 + 5
using namespace std;
int dp[MAXM] = {0};
int W[MAXN] = {0};
int V[MAXN] = {0};
int main()
{
#ifdef LOCAL
    freopen("ADV-144.in", "r", stdin);
#endif
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; ++i) cin >> W[i] >> V[i];
    for(int i = 1; i <= n; ++i)
        for(int c = m; c >= W[i]; --c)
            dp[c] = max(dp[c], dp[c - W[i]] + V[i]); 
    cout << dp[m] << endl;
    return 0;
}